package ru.spb.osll.myfit.server.parser;

import java.util.HashSet;
import java.util.Set;

import ru.spb.osll.myfit.server.Converter;

public class PageElementParserFactory {
  private final Set<IPageElementParser> m_availableParsers = new HashSet<IPageElementParser>();
  private final IPageElementParser m_defaultParser;
  
  public PageElementParserFactory(Converter converter) {
    m_defaultParser = new WikiElementParser(converter);
    m_availableParsers.add(new TableElementParser());
    m_availableParsers.add(new ContentElementParser());
    m_availableParsers.add(new IncludeElementParser());
    m_availableParsers.add(new PathElementParser());
  }
  
  public IPageElementParser getParser(String line){
    for(IPageElementParser parser: m_availableParsers){
      if(parser.matches(line)){
        return parser;
      }
    }
    return m_defaultParser;
  }
  
  public IPageElementParser getDefaultParser(){
    return m_defaultParser;
  }
}
